package DataStructureAndAlgorithm.Tedukuri.拓扑排序;

import java.util.*;
//链接：https://www.acwing.com/problem/content/description/166/
class AcWing_164{

    static int n,m;
    static int N = 30010;
    static int idx = 0;
    static int[] e = new int[N];
    static int[] ne = new int[N];
    static int[] h = new int[N];

    static int[] d = new int[N];
    static int[] seq = new int[N];
    //每一个点都可以用一连串的二进制串表示，从而压缩空间
    static BitSet[] f = new BitSet[N];

    static void add(int a,int b){
        e[idx] = b; ne[idx] = h[a]; h[a] = idx++;
    }

    static void topSort(){
        Queue<Integer> queue = new LinkedList<>();
        //将所有入度为0的点入队
        for (int i = 1; i <= n; i++){
            if (d[i] == 0){
                queue.offer(i);
            }
        }

        int k = 0;

        while (!queue.isEmpty()){
            int t = queue.poll();
            //将当前点加入到拓扑序列的后面
            seq[k++] = t;
            for (int i = h[t]; i != -1; i = ne[i]){
                int j = e[i];
                //如果去掉了与t点连接的边后，入度变为0，则入队
                if (--d[j] == 0){
                    queue.offer(j);
                }
            }

        }

    }

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        Arrays.fill(h,-1);
        n = in.nextInt();
        m = in.nextInt();
        int a,b;
        for (int i = 0; i < m; i++){
            a = in.nextInt();
            b = in.nextInt();
            add(a,b);
            //a到b点，所以，b点的入度加一
            d[b]++;
        }

        topSort();
        //从后往前求
        for (int i = n - 1; i >= 0; i--){
            int j = seq[i];
            f[j] = new BitSet();
            //每个点都能到自己
            f[j].set(j,true);
            //dp的常用思路
            for (int p = h[j]; p != -1; p = ne[p]){
                f[j].or(f[e[p]]);
            }
        }

        for (int i = 1; i <= n; i++){
            System.out.println(f[i].cardinality());
        }

        in.close();
    }
}